package com.java.comprehensive.design.behavioral_model.observer_pattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 窦绍飞
 * @create 2023/2/23
 */
public class SubscriptionSubject implements Subject {

	private List<Obsever> wxList;

	public void attach(Obsever obsever) {
		if (wxList == null) {
			wxList = new ArrayList<Obsever>();
		}
		wxList.add(obsever);
	}

	public void detach(Obsever obsever) {
		if (wxList != null) {
			wxList.remove(obsever);
		}
	}

	public void notify(String message) {
		for (Obsever obsever : wxList) {
			obsever.update(message);
		}
	}
}
